package cn.tworice.common.utils;


import cn.tworice.common.entity.Admin;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Date;

public class TokenUtil {
    public static String getAdminToken(Admin admin) {
        long time = System.currentTimeMillis() + (1000 * 60 * 60 * 24);
        Date date = new Date();
        date.setTime(time);
        return  JWT.create()
                .withAudience(admin.getId()) // 将用户ID存入token中
                .withExpiresAt(date)    // 设置过期时间
                .sign(Algorithm.HMAC256(admin.getId()));// 设置私钥为用户ID
    }
}